A major objective in graphics rendering is to produce images that are so realistic that the observer believes the image is real. A fundamental difficulty in achieving total visual realism is the complexity of accurately representing real world visual effects. A scene can include a wide variety of textures, subtle color gradations, reflections, translucency, etc.
One important way to make images more realistic is to determine how objects in a scene cast shadows and then represent these shadows in the rendered image. Shadows enhance the realism of an image because they give a two-dimensional image a three-dimensional feel.
The addition of shadows to the rendering of a complex model can greatly enhance the understanding of that model's geometry. The human visual system uses shadows as a cue for depth and shape. Consequently, shadows are very useful for conveying the three dimensional nature of rendered objects and for adding realism to computer generated scenes.
Prior art FIG. 1 illustrates a scene 100 where shadowing is needed during processing in a graphics pipeline. As shown in FIG. 1, a particular scene 100 includes a light source 104, a light obstructing surface 102, and a plurality of objects 106. Due to the relative orientation of the light source 104, objects 106 and surface 102, a shadow should be shown on certain objects 106 where the surface 102 obstructs light from the light source 104.
The utilization of shadow volumes is a technique by which a graphics pipeline may determine which objects 106 in the scene 100 should be rendered with a shadow. In particular, a shadow bit is maintained for each pixel in a frame buffer which indicates whether the objects 106 are in or out of the shadow projected by the surface 102.
Since the shadow volume technique takes place in a frame buffer of a graphics pipeline, it may be referred to as an image space algorithm. While shadowing may be trivial in a scene with one obstructing surface 102, rendering may be complicated when multiple overlapping obstructing surfaces 102 exist.
Prior art FIG. 2 illustrates a scene 200 where shadowing is complicated by the involvement of multiple intersecting overlapping surfaces 102. In such more complex environments, a technique of “counting” is employed. As shown in Prior art FIG. 2, a plurality of obstructing surfaces 102 cast a plurality of shadow volumes each defined by a plurality of boundary primitives 202.
Such boundary primitives 202 are either front-facing or back-facing with respect to how they are viewed. In the context of the present description, a primitive is front-facing or back-facing based on whether the area of the primitive in screen space is positive or negative, or the ordering of vertices of the primitive is clockwise or counterclockwise. Note Prior art FIG. 2 where front-facing and back-facing primitives are designated with an “F” and “B,” respectively.
Prior art FIG. 3 illustrates a method 300 for counting shadow volumes, in accordance with the prior art. Initially, in operation 302, a depth buffer and a stencil buffer are cleared after which the scene 200 is rendered with the light source 102 disabled during a first rendering pass. Once this pass is rendered, the color of all pixels in the frame buffer is as if every pixel were in shadow with respect to the light. Note operation 304. It should be noted that such operation affords a depth state of a closest object in the scene 200.
Next, in operation 306, primitives constituting the geometry of the scene's shadow volumes are drawn in the scene 200 during a second rendering pass. During the second pass, no color depth buffer writes take place in order to prevent disturbing results of the first rendering pass. Further, any back-facing shadow volume primitives are culled. For the remaining front-facing primitives, a per-pixel stencil value is incremented for each boundary between an eye position 206 and a subject object 204. This is accomplished by incrementing the per-pixel stencil value whenever the depth test passes. Since there are three front-facing primitive boundaries, such stencil value has the value of +3 after operation 306.
Next, in operation 308, shadow volume primitives are again drawn in the scene during a third rendering pass. Similar to the second pass, no color depth buffer writes take place in order to prevent disturbing results of the previous rendering passes. In operation 308, any front-facing primitives are culled. For the remaining back-facing primitives, a per-pixel stencil value is decremented for each boundary between the eye position 206 and the subject object 204. This is accomplished by decrementing the per-pixel stencil value whenever the depth test passes. Since there are three back-facing primitive boundaries, such stencil value has the value of “0” after operation 306.
The scene may then be rendered again during a fourth rendering pass in operation 310. During the fourth rendering pass, the light source 102 is enabled. Color writes are re-enabled for this rendering pass. Moreover, pixels are only updated if it is determined that the pixel is outside a shadow volume, as indicated by the stencil value being equal to “0.” In the case of object 204 of Prior art FIG. 2, such associated pixels would be updated to show light. However, in the case of object 206, no light would be shown since the stencil value would be +2 so the stencil test fails which leaves the pixel unchanged from the initial shadowed rendering pass, etc.
One problem that results from the method 300 of Prior art FIG. 3 stems from the fact that the shadow volumes must be rendered twice during operations 306 and 308. The requirement that these rendering passes be separate operations 306 and 308 is prompted by the fact that traditional stencil value testing can not distinguish between front-facing and back-facing primitives. As such, the front-facing and back-facing primitives must be handled separately, in different rendering passes. This results in an efficiency problem that causes lower performance during graphics processing.